﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace MusicAcademy
{
    public partial class ListOfRegisters : Form
    {
        public int SelectedID;
        public string StudentName;
        public string TeacherName;
        public string ToolName;

        public ListOfRegisters()
        {
            InitializeComponent();
        }

        private void RefreshGrid()
        {
            fullRegisterTableAdapter.Fill(musicAcademyDataSet.FullRegister, txtStudentName.Text, txtTeacherName.Text, txtToolName.Text);
        }

        private void ListOfRegisters_Load(object sender, EventArgs e)
        {
            RefreshGrid();
        }

        private void txtStudentName_TextChanged(object sender, EventArgs e)
        {
            RefreshGrid();
        }

        private void txtToolName_TextChanged(object sender, EventArgs e)
        {
            RefreshGrid();
        }

        private void txtTeacherName_TextChanged(object sender, EventArgs e)
        {
            RefreshGrid();
        }

        private void btnOK_Click(object sender, EventArgs e)
        {
            if (grdRegister.SelectedRows.Count > 0)
            {
                SelectedID = Convert.ToInt32(grdRegister.SelectedRows[0].Cells["ID"].Value);
                StudentName = grdRegister.SelectedRows[0].Cells["_StudentName"].Value.ToString();
                TeacherName = grdRegister.SelectedRows[0].Cells["_TeacherName"].Value.ToString();
                ToolName = grdRegister.SelectedRows[0].Cells["_ToolName"].Value.ToString();
                DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("لطفا یک رکورد را انتخاب نمایید.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }

        private void grdRegister_CellDoubleClick(object sender, DataGridViewCellEventArgs e)
        {
            if (grdRegister.SelectedRows.Count > 0)
            {
                SelectedID = Convert.ToInt32(grdRegister.SelectedRows[0].Cells["ID"].Value);
                StudentName = grdRegister.SelectedRows[0].Cells["_StudentName"].Value.ToString();
                TeacherName = grdRegister.SelectedRows[0].Cells["_TeacherName"].Value.ToString();
                ToolName = grdRegister.SelectedRows[0].Cells["_ToolName"].Value.ToString();
                DialogResult = System.Windows.Forms.DialogResult.OK;
                this.Close();
            }
            else
            {
                MessageBox.Show("لطفا یک رکورد را انتخاب نمایید.", "خطا", MessageBoxButtons.OK, MessageBoxIcon.Exclamation);
            }
        }
    }
}
